package scalaoop

object  TestApp{
  def main(args: Array[String]): Unit = {
    //函数做为方法的参数
    println(mm1(5,6,f2))
    //参数传入方法，当传入了方法，方法会被转换成函数
    println(mm1(5,6,m2))
    //_将方法转化成了函数
    println(mm1(5,6,m2 _))
    //只要满足函数参数聚合要求即可
    println(mm1(5,6,f3))

    //函数做函数的参数
    println(f4(5,6,f3))

  }
  def m2(x:Int,y:Int):Int=x+y

  //函数
  val f1: (Int) => Double = (value:Int) => value.toDouble

  val f2: (Int, Int) => Int = (x:Int, y:Int) => x+y

  val f3: (Int, Int) => Int = (x:Int, y:Int) => x*y

  //函数做了方法的参数
  //第二个参数是一个函数 (Int, Int) => Int
  //ff 可以是函数，也可以是方法，只要满足 (Int, Int) => Int 接收两个Int 聚合成一个
  def mm1(x:Int,y:Int,ff:(Int, Int) => Int) = ff(x,y)

  //函数做函数的参数
  val f4: (Int, Int, (Int, Int) => Int) => Int = (x:Int, y:Int, ff:(Int, Int) => Int) => ff(x,y)

}